<?php
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\library\Letter;
use app\common\library\Insert;
use think\Model;
class Collect extends Model{
	public function vod_insert($data=[],$param=[]){
		$Insert= new Insert;
		$msg='';
		$config=F('_collect/config');
		$collect=$config;
		$inspect=!empty($collect['vod']['inspect'])?$collect['vod']['inspect']:[];
		//过滤不必要的字段
		unset($data['vod_id'],$data['vod_pay'],$data['vod_trysee'],$data['vod_jumpurl']);
		if(empty($data['vod_name'])){
			return ['code'=>-2,'msg'=>'<span class=\"text-danger\">影片名称为空,跳过</span>'];
		}
        if(!empty($collect['vod']['filter_name']) && in_array($data['vod_name'],$collect['vod']['filter_name'])) {
			return ['code'=>-2,'msg'=>'<span class=\"text-danger\">影片名称在过滤中跳过,跳过</span>'];
        }				
		if($collect['vod']['empty_url']==1 && empty($data['vod_url'])){
			return ['code'=>-2,'msg'=>'<span class=\"text-danger\">播放地址为空,跳过</span>'];
		}
		if(empty($data['vod_cid'])){
			return ['code'=>-2,'msg'=>'<span class=\"text-danger\">未匹配到对应栏目分类,跳过</span>'];
		}
		if(!empty($collect['vod']['time'])){
			$data['vod_addtime']=time();
		}else{
			$data['vod_addtime'] =!empty($data['vod_addtime']) ? strtotime($data['vod_addtime']) : time();
		}
		//不添加播放地址设置为空
		if(empty($collect['vod']['add_url'])){
			$data['vod_play'] = '';
			$data['vod_url'] = '';		    
		}			
		//播放组名替换
		if(!empty($collect['vod']['replace_playname']) && !empty($data['vod_play'])){
		    $data['vod_play'] =$this->replace_play($data['vod_play']);
		}		
		//视频标题替换
		if(!empty($collect['vod']['replace_name'])){
		    $data['vod_name'] = str_replace($collect['vod']['replace_name']['find'], $collect['vod']['replace_name']['replace'],$data['vod_name']);
		}
		//过滤本地不存在播放组或禁采播放组
		$filter_url='';
		if(!empty($collect['vod']['filter_url']) && !empty($data['vod_play']) && !empty($data['vod_url']) ){
		    $play =model('play')->filter_play_array($data['vod_play'],$data['vod_url']);
		    $data['vod_play'] = $play['vod_play'];
		    $data['vod_url'] = $play['vod_url'];			
			if(empty($play['vod_play']) && empty($play['vod_url'])){
				$filter_url='<span class=\"text-warning\">播放组过滤后为空</span>';
			}
		}	
		
 		if(!empty($collect['vod']['status'])){
			$data['vod_status'] = 1;
		}else{
			$data['vod_status'] = 0;
		}
		if(!empty($data['vod_keywords'])){
		    $data['vod_mcid']=model('Mcat')->get_mcid($data['vod_cid'],$data['vod_keywords']);
	    }
		$data['vod_lock'] = intval($data['vod_lock']);
		$data['vod_year'] = intval($data['vod_year']);
        $data['vod_total'] = (string)preg_replace('/\D/s', '',$data['vod_total']);
		$data['vod_continu'] = (string)preg_replace('/\D/s', '',$data['vod_continu']);
		$data['vod_length'] = (string)preg_replace('/\D/s', '',$data['vod_length']);
		$data['vod_isend'] = intval($data['vod_isend']);
        if(empty($data['vod_isend']) && !empty($data['vod_continu'])){
            $data['vod_isend'] = 0;
        }
		if($data['vod_filmtime'] ){
			if(is_int($data['vod_filmtime']) && strlen($data['vod_filmtime'])>=10){
			$data['vod_filmtime']=$data['vod_filmtime'];	
			}else{
			$data['vod_filmtime']=strtotime($data['vod_filmtime'].' 0:0:0');
			}
		}		
        $data['vod_actor'] = (string)format_text($data['vod_actor']);
        $data['vod_director'] = (string)format_text($data['vod_director']);	
        $data['vod_keywords'] = (string)format_text($data['vod_keywords']);
        $data['vod_tag'] = (string)format_text($data['vod_tag']);
        $data['vod_diantai'] = (string)format_text($data['vod_diantai']);
        $data['vod_tvexp']=(string)$data['vod_tvexp'];		
 		if($collect['vod']['hits_min']>0 && $collect['vod']['hits_max']>0){
			$data['vod_hits'] = mt_rand($collect['vod']['hits_min'],$collect['vod']['hits_max']);
			$data['vod_hits_day'] = mt_rand($collect['vod']['hits_min'],$collect['vod']['hits_max']);
			$data['vod_hits_week'] = mt_rand($collect['vod']['hits_min'],$collect['vod']['hits_max']);
			$data['vod_hits_month'] = mt_rand($collect['vod']['hits_min'],$collect['vod']['hits_max']);
		}
		if($collect['vod']['gold_min']>0 && $collect['vod']['gold_max']>0){
			$data['vod_gold'] = mt_rand($collect['vod']['gold_min'],$collect['vod']['gold_max']);
		}		
		if($collect['vod']['updown_min']>0 && $collect['vod']['updown_max']>0){
			$data['vod_up'] = mt_rand($collect['vod']['updown_min'],$collect['vod']['updown_max']);
			$data['vod_down'] = mt_rand($collect['vod']['updown_min'],$collect['vod']['updown_max']);
		} 
		if(!empty($collect['vod']['ciku'])){
			$data['vod_content']=$Insert->ciku_add('vod',$data['vod_content']);
		}
        if(empty($data['vod_play'])) $data['vod_play']='';
        if(empty($data['vod_url'])) $data['vod_url']='';
		if(empty($data['vod_content'])) $data['vod_content']='';
		//验证播放地址
		$play_list_db = model('vod')->vod_url_check($data['vod_play'],$data['vod_url']);
        $data['vod_play'] = $play_list_db['vod_play'];
		$data['vod_url'] = $play_list_db['vod_url'];	
		$info = db('urls')->alias('u')->join('vod v','v.vod_id=u.urls_id','RIGHT')->where('urls_reurl','eq',$data['vod_reurl'])->find();
		//不存在相同来源
		if(empty($info['vod_id'])){
		    $where = [];
		    $where['vod_name'] = $data['vod_name'];
			$zi=false;
            if (in_array(3,$inspect)){
                    $where['vod_cid'] = $data['vod_cid'];
            }
            if (in_array(4,$inspect)){
                    $where['vod_actor'] = ['like',like_array($data['vod_actor']), 'OR'];
            }			
            if (in_array(5,$inspect)){
                    $where['vod_director'] = $data['vod_director'];
            }
            if (in_array(6,$inspect)){
                    $where['vod_year'] = $data['vod_year'];
            }
            if (in_array(7,$inspect)){
                    $where['vod_area'] = $data['vod_area'];
            }			
            if(!empty($where['vod_actor']) && !empty($where['vod_director'])){
                    $zi = true;
                    $GLOBALS['zi'] = [
                        'vod_actor' => $where['vod_actor'],
                        'vod_director' => $where['vod_director']
                    ];
                    unset($where['vod_actor'],$where['vod_director']);
            }
            if($zi===false){
                $info = db('Vod')->where($where)->find();
            }else{
                $info = db('Vod')->where($where)->where(function($query){
                    $query->where('vod_director',$GLOBALS['zi']['vod_director'])
                          ->whereOr('vod_actor',$GLOBALS['zi']['vod_actor']);
                })->find();
            }			
		}
		//print_r($data['story_content']);
		//不存在添加数据
		if(empty($info['vod_id'])){
			if($param['status']==1){
				return ['code'=>-1,'msg'=>'<span class=\"text-danger\">资源锁定不添加新数据</span> '];
			}			
		    if(!empty($collect['vod']['tag'])){
		        $data['vod_tag']=zanpian_get_tag($data['vod_name'],$data['vod_content']);
	        }
			if(!empty($collect['vod']['pic'])){
				config('upload.upload_http',1);
				$file=model('Img')->down_load(trim($data['vod_pic']),'vod');	
				$data['vod_pic']=$file['file'];
			}
		    $Letter = new Letter();			
			$data['vod_letters'] = $Letter->getletters(trim($data['vod_name']),1);
			$vodid=db('vod')->insertGetId($data);
			
			//关联写入
		    if($vodid){
                if($data['vod_mcid']){				
			        model('Mcid')->mcid_updata($vodid,1,$data['vod_mcid']);
                }
                if($data['vod_tag']){				
			        model('Tag')->tag_updata($vodid,1,$data['vod_tag']);
                }
                if($data['vod_diantai']){				
			        model('Vodtv')->tv_updata($vodid,1,$data['vod_diantai']);
                }
                if($data['vod_actor']){				
			        model('Actors')->actors_updata($vodid,1,$data['vod_actor']);
                }
                if($data['vod_director']){				
			        model('Actors')->actors_updata($vodid,2,$data['vod_director']);
                }
                if($data['vod_reurl']){				
			        model('Urls')->urls_updata($vodid,$data['vod_reurl']);
                }	
			    //关联写入剧情
			    if(!empty($data['story_part']) && !empty($collect['vod']['add_story'])){
					$story=[];
                    $story['story_vid']= $vodid;
                    $story['story_reurl']= (string)$data['story_reurl'];
					$story['story_content']= (string)$data['story_content'];
	                $addstory=$Insert->story_post($story,$data['story_part']);
				    $storymsg.=' <span class=\"text-success\">剧情添加成功</span> ';
				    if($addstory['code']!=1){
					    $storymsg=$addstory['msg'];
				    }	
			    }
			    //关联写入角色
			    if(!empty($data['actor_role']) && !empty($collect['vod']['add_actor'])){
				    $actor=[];
                    $actor['actor_vid']= $vodid;
                    $actor['actor_reurl']= (string)$data['actor_reurl'];				
	                $addactor=$Insert->actor_post($actor,$data['actor_role']);
				    $actormsg.=' <span class=\"text-success\">角色添加成功</span> ';
				    if($addactor['code']!=1){
					    $actormsg=$addactor['msg'];
				    }            			
			    }
			    //关联写入台词
			    if(!empty($data['vod_lines']) && !empty($collect['vod']['add_lines'])){	
				    $lines=[];
                    $lines['vod_id']= $vodid;				
	                $addlines=$Insert->lines_post($lines,$data);
				    $linesmsg.=' <span class=\"text-success\">台词添加成功</span> ';
				    if($addlines['code']!=1){
					    $linesmsg=$addlines['msg'];
				    }            			
			    }
			    //关联写入歌曲
			    if(!empty($data['vod_music']) && !empty($collect['vod']['add_music'])){	
				    $music=[];
                    $music['vod_id']= $vodid;				
	                $addmusic=$Insert->music_post($music,$data);
				    $musicmsg.=' <span class=\"text-success\">台词添加成功</span> ';
				    if($addmusic['code']!=1){
					    $musicmsg=$addmusic['msg'];
				    }            			
			    }				
                $data['vod_id']=$vodid;				
                return ['code'=>$vodid,'msg'=>$filter_url.' <span class=\"text-success\">添加成功 视频ID:'.$vodid.'</span> '.$storymsg.$actormsg.$linesmsg.$musicmsg.model('Push')->url(1,$data,'',2)];				
			}
			return ['code'=>-1,'msg'=>'<span class=\"text-danger\">视频添加失败</span> '.$storymsg.$linesmsg.$musicmsg];				
		}else{
		//更新存在数据
            if($info['vod_lock'] == 1){
                return ['code'=>-2,'msg'=>'<span class=\"text-danger\">数据锁定不更新,跳过</span> <span class=\"text-success\">视频ID:'.$info['vod_id'].'</span> '];
            }
			$uprule=!empty($collect['vod']['uprule'])?$collect['vod']['uprule']:[];
            if(empty($uprule) && empty($collect['vod']['up_value'])){
				return ['code'=>-2,'msg'=>'<span class=\"text-danger\">没有选择更新规则或小于不存在更新,跳过</span> <span class=\"text-success\">视频ID:'.$info['vod_id'].'</span> '];
            }
            $updata=[];
			if(!empty($filter_url)){
				$msg.=$filter_url;
			}
            if(in_array(1,$uprule) && !empty($data['vod_play']) && !empty($data['vod_url'])){
			    // 检测播放地址是否变化
		        $play_list_old = $this->vod_url_array($info['vod_play'], $info['vod_url']);
		        $play_list_new = $this->vod_url_array($data['vod_play'], $data['vod_url']);
				if(empty($play_list_old)){
				   $play_list_merge = $play_list_new;//合并新旧地址	
				}else{
				   $play_list_merge = @array_merge($play_list_old,$play_list_new);//合并新旧地址
				}
				$play_list_db = $this->vod_array_url($play_list_merge);//还原入库格式
				if(empty($play_list_db)){
					$msg.='<span class=\"text-warning\">播放地址为空</span>';
				}
		        elseif($info['vod_url']==$play_list_db['vod_url']){
			        $msg.='<span class=\"text-warning\">播放地址未变化</span>';
		        }else{
                    $new_play=array_diff(explode('$$$',$play_list_db['vod_play']),explode('$$$',$info['vod_play']));
					if($new_play){
						$msg.='<span class=\"text-success\"> 新增 '.implode(' ',$new_play).' 成功</span>';
						
					}else{
						$msg.='<span class=\"text-success\">更新播放地址成功</span>';
					}
		            $updata['vod_url']=$play_list_db['vod_url'];
		            $updata['vod_play']=$play_list_db['vod_play'];
			    }	
            }else{
				$msg.='<span class=\"text-warning\">没有选择更新地址规则</span>';
			} 
			$zl=false;
			if(in_array(2,$uprule) && !empty($data['vod_continu']) && $data['vod_continu']!=$info['vod_continu']){
				$updata['vod_continu']=$data['vod_continu'];
				$zl=true;				
			}
			if(in_array(3,$uprule) && !empty($data['vod_total']) && $data['vod_total']!=$info['vod_total']){
				$updata['vod_total']=$data['vod_total'];
				$zl=true;
			}
			if(in_array(4,$uprule) && !empty($data['vod_length']) && $data['vod_length']!=$info['vod_length']){
				$updata['vod_length']=$data['vod_length'];
				$zl=true;				
			} 
			if(in_array(5,$uprule) && !empty($data['vod_aliases']) && $data['vod_aliases']!=$info['vod_aliases']){
				$updata['vod_aliases']=$data['vod_aliases'];
				$zl=true;
			}
			if(in_array(6,$uprule) && !empty($data['vod_title']) && $data['vod_title']!=$info['vod_title']){
				$updata['vod_title']=$data['vod_title'];
				$zl=true;
			}
			if(in_array(7,$uprule) || !empty($collect['vod']['up_value']) && !empty($data['vod_mcid'])){
				if($collect['vod']['up_value']==1 && $data['vod_mcid']>$info['vod_mcid'] ){
				    $mcid=implode(',',array_filter(array_unique(explode(',',format_text($info['vod_mcid'].','.$data['vod_mcid'])))));
					$updata['vod_mcid']=$mcid;
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && $data['vod_mcid']!=$info['vod_mcid'] ){
				    $mcid=implode(',',array_filter(array_unique(explode(',',format_text($info['vod_mcid'].','.$data['vod_mcid'])))));
					$updata['vod_mcid']=$mcid;
				    $zl=true;
				}				
			}
            if(in_array(8,$uprule) && !empty($data['vod_weekday']) && $data['vod_weekday']!=$info['vod_weekday']){
				$updata['vod_weekday']=$data['vod_weekday'];
				$zl=true;
			}
            if(in_array(9,$uprule) && !empty($data['vod_actor'])){
				if($collect['vod']['up_value']==1 && $data['vod_actor']>$info['vod_actor'] ){
				    $actor=implode(',',array_filter(array_unique(explode(',',format_text($data['vod_actor'])))));
				    $updata['vod_actor']=$actor;
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && $data['vod_actor']!=$info['vod_actor'] ){
                    $actor=implode(',',array_filter(array_unique(explode(',',format_text($info['vod_actor'].','.$data['vod_actor'])))));
				    $updata['vod_actor']=$actor;
				    $zl=true;
				}				
			}
			if(!empty($collect['vod']['up_value']) && !empty($data['vod_director'])){
				if($collect['vod']['up_value']==1 && $data['vod_director']>$info['vod_director'] ){
				    $updata['vod_director']=$data['vod_director'];
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && $data['vod_director']!=$info['vod_director'] ){
				    $updata['vod_director']=$data['vod_director'];
				    $zl=true;
				}
			}
            if(in_array(11,$uprule) && !empty($data['vod_year']) && empty($info['vod_year'])){
				$updata['vod_year']=$data['vod_year'];
				$zl=true;
			}
            if(in_array(12,$uprule) && !empty($data['vod_area']) && empty($info['vod_area'])){
				$updata['vod_area']=$data['vod_area'];
				$zl=true;
			}
            if(in_array(13,$uprule) && !empty($data['vod_language']) && empty($info['vod_language'])){
				$updata['vod_language']=$data['vod_language'];
				$zl=true;
			}
            if(in_array(14,$uprule) && (substr($info['vod_pic'],0, 4) == 'http' || substr($info['vod_pic'],0, 2) == '//' || empty($info['vod_pic']) ) && $data['vod_pic']!=$info['vod_pic']){
				if(!empty($collect['vod']['pic'])){
				    config('upload.upload_http',1);
				    $file=model('Img')->down_load(trim($data['vod_pic']),'vod');	
				    $data['vod_pic']=$file['file'];
			    }
				$updata['vod_pic']=$data['vod_pic'];
				$zl=true;
			}
			if(in_array(15,$uprule)&& !empty($data['vod_content'])){
				if($collect['vod']['up_value']==1 && $data['vod_content']>$info['vod_content'] ){
				    $updata['vod_content']=$data['vod_content'];
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && ($data['vod_content']!=$info['vod_content'] || empty($info['vod_content']))){
				    $updata['vod_content']=$data['vod_content'];
				    $zl=true;
				}
			}		
            if(in_array(16,$uprule) && !empty($data['vod_tag'])){
				if($collect['vod']['up_value']==1 && $data['vod_tag']>$info['vod_tag'] ){
				    $updata['vod_tag']=$data['vod_tag'];
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && ($data['vod_tag']!=$info['vod_tag'] || empty($info['vod_tag']))){
				    $updata['vod_tag']=$data['vod_tag'];
				    $zl=true;
				}
			}		
            if(in_array(17,$uprule) && !empty($data['vod_filmtime']) && empty($info['vod_filmtime'])){
				$updata['vod_filmtime']=$data['vod_filmtime'];
				$zl=true;
			}
            if(in_array(18,$uprule) && !empty($data['vod_diantai'])){
				if($collect['vod']['up_value']==1 && $data['vod_diantai']>$info['vod_diantai'] ){
				    $diantai=implode(',',array_filter(array_unique(explode(',',format_text($data['vod_diantai'])))));
				    $updata['vod_diantai']=$diantai;
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && ($data['vod_diantai']!=$info['vod_diantai'] || empty($info['vod_diantai']))){
                    $diantai=implode(',',array_filter(array_unique(explode(',',format_text($info['vod_diantai'].','.$data['vod_diantai'])))));
				    $updata['vod_diantai']=$diantai;
				    $zl=true;
				}				
			}
            if(in_array(19,$uprule) && !empty($data['vod_tvcont'])){
				if($collect['vod']['up_value']==1 && $data['vod_tvcont']>$info['vod_tvcont'] ){
				    $updata['vod_tvcont']=$data['vod_tvcont'];
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && ($data['vod_tvcont']!=$info['vod_tvcont'] || empty($info['vod_tvcont']))){
				    $updata['vod_tvcont']=$data['vod_tvcont'];
				    $zl=true;
				}
			}
            if(in_array(20,$uprule) && !empty($data['vod_tvexp'])){
				if($collect['vod']['up_value']==1 && $data['vod_tvexp']>$info['vod_tvexp'] ){
				    $updata['vod_tvexp']=$data['vod_tvexp'];
				    $zl=true;
				}elseif($collect['vod']['up_value']==2 && ($data['vod_tvexp']!=$info['vod_tvexp'] || empty($info['vod_tvexp']))){
				    $updata['vod_tvexp']=$data['vod_tvexp'];
				    $zl=true;
				}
			}
            if(in_array(21,$uprule) && !empty($data['vod_doubanid']) && empty($info['vod_doubanid'])){
				$updata['vod_doubanid']=$data['vod_doubanid'];
				$zl=true;
			}
			if($zl){
				$msg.=' <span class=\"text-success\">资料更新成功</span> ';
			}
			//关联写入剧情
			if(!empty($data['story_part']) && !empty($collect['vod']['add_story'])){
				$story=[];
                $story['story_vid']= $info['vod_id'];
                $story['story_reurl']= $data['story_reurl'];
	            $addstory=$Insert->story_post($story,$data['story_part']);
				$storymsg.=' <span class=\"text-success\">更新剧情成功</span> ';
				if($addstory['code']!=1){
					$storymsg=$addstory['msg'];
				}	
			}		
			//关联写入角色
			if(!empty($data['actor_role']) && !empty($collect['vod']['add_actor'])){
				$actor=[];
                $actor['actor_vid']= $info['vod_id'];
                $actor['actor_reurl']= $data['actor_reurl'];				
	            $addactor=$Insert->actor_post($actor,$data['actor_role']);
				$actormsg.=' <span class=\"text-success\">更新角色成功</span> ';
				if($addactor['code']!=1){
					$actormsg=$addactor['msg'];
				}            			
			}
			//关联写入台词
			if(!empty($data['vod_lines']) && !empty($collect['vod']['add_lines'])){
				$lines=[];
                $lines['vod_id']= $info['vod_id'];				
	            $addlines=$Insert->lines_post($lines,$data);
				$linesmsg.=' <span class=\"text-success\">更新台词成功</span> ';
				if($addlines['code']!=1){
					$linesmsg=$addlines['msg'];
				}            			
			}
			//关联写入歌曲
			if(!empty($data['vod_music']) && !empty($collect['vod']['add_music'])){
				$music=[];
                $music['vod_id']= $info['vod_id'];				
	            $addmusic=$Insert->music_post($music,$data);
				$musicmsg.=' <span class=\"text-success\">更新歌曲成功</span> ';
				if($addmusic['code']!=1){
					$musicmsg=$addmusic['msg'];
				}            			
			}			
			if(count($updata)>0){
				$updata['vod_addtime']=$data['vod_addtime'];
                $updata['vod_reurl']=implode(',',array_filter(array_unique(explode(',',$info['vod_reurl'].','.$data['vod_reurl']))));
                $result = db('vod')->where('vod_id',$info['vod_id'])->update($updata);
		        if($result !== false){
					model('Manage')->DelCache(1,$info['vod_id']);
                    if($updata['vod_mcid']){				
			            model('Mcid')->mcid_updata($info['vod_id'],1,$updata['vod_mcid']);
                    }
                    if($updata['vod_tag']){				
			            model('Tag')->tag_updata($info['vod_id'],1,$updata['vod_tag']);
                    }
                    if($updata['vod_diantai']){				
			            model('Vodtv')->tv_updata($info['vod_id'],1,$updata['vod_diantai']);
                    }
                    if($updata['vod_actor']){				
			            model('Actors')->actors_updata($info['vod_id'],1,$updata['vod_actor']);
                    }
                    if($updata['vod_director']){				
			           model('Actors')->actors_updata($info['vod_id'],2,$updata['vod_director']);
                    }
                    if($updata['vod_reurl']){				
			           model('Urls')->urls_updata($info['vod_id'],$updata['vod_reurl']);
                    }
			        return ['code'=>$info['vod_id'],'msg'=>$msg.$storymsg.$actormsg.$linesmsg.$musicmsg.model('Push')->url(1,$updata,'up',2).' <span class=\"text-success\">视频ID:'.$info['vod_id'].'</span> '];	
		        }else{
			        return ['code'=>-1,'msg'=>'<span class=\"text-danger\">更新失败,跳过</span>'];					
		        }				
            }else{
			   return ['code'=>$info['vod_id'],'msg'=>' <span class=\"text-warning\">原数据相同不更新,跳过。 </span> '.$storymsg.$actormsg.$linesmsg.$musicmsg.'  <span class=\"text-success\">视频ID:'.$info['vod_id'].'</span> '];	
			}			
			
		}
	}	
    // 格式化播放地址
	function vod_url_array($vod_play,$vod_url){
		if(empty($vod_play) || empty($vod_url)){
			return false;
		}	
		$old_play = is_array($vod_play)?$vod_play:explode('$$$',$vod_play);
		$old_url = is_array($vod_url)?$vod_url:explode('$$$',$vod_url);
		$old_array = array();
		$sid = array();
		foreach($old_play as $key=>$value){
			$url_one = explode(chr(13),str_replace(array("\r\n", "\n", "\r"), chr(13),$old_url[$key]));
			foreach($url_one as $key_son=>$value_son){
				$old_array[$value.'-'.intval($sid[$value]).'-'.$key_son] = $value_son;
			}
			$sid[$value] = +1;
		}
		return $old_array;
	}
	//重组播放地址
	function vod_array_url($play_list_merge){
		if(empty($play_list_merge)){
			return false;
		}		
		foreach($play_list_merge as $key=>$value){
			list($play_name,$play_sid,$play_pid) = explode('-',$key);
			$play[$play_name.$play_sid] = $play_name;
			$array_url[$play_name.$play_sid][$play_pid] = $value;
		}
		
		//还原单组播放地址
		foreach($array_url as $key=>$value){
			$url[$key] = implode(chr(13),array_unique($value));
		}

		return array('vod_play'=>implode('$$$',$play),'vod_url'=>implode('$$$',$url));
	}	
	//播放组名替换
	public function replace_play($play){
		if(empty($play)){
			return false;
		}		
		$config=F('_collect/config');
		$replace_play=$config['vod']['replace_playname'];
		if($config['vod']['replace_playname']){
            $replace_key=array_keys($replace_play);
		    $replace_values=array_values($replace_play);
		    $play=str_replace($replace_key,$replace_values,$play);
             return $play;
		}else{
			return $play;
		}
	}			
	
}